home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11417 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: naic.wpafb.af.mil!jjr189
  2. From: jjr189@naic.wpafb.af.mil (jimmie j rohrer/scde/77815)
  3. Newsgroups: comp.lang.c++
  4. Subject: ?Callbacks / Pointer to member functions?
  5. Date: 14 Mar 1996 14:39:56 GMT
  6. Organization: NAIC, Wright Patterson AFB
  7. Distribution: world
  8. Message-ID: <4i9b3s$7tt@serveru1.naic.wpafb.af.mil>
  9. NNTP-Posting-Host: scd3.naic.wpafb.af.mil
  10. Keywords: Callbacks Pointers Member Functions
  11.  
  12. Hello,
  13.     I'm trying to add some motif stuff to my C++ program but I'm having a problem with callbacks.  I have classes that implement gui components but I don't know how to pass a pointer to a member function to motif, so that motif can call the member function as a callback.  Can you help?  Ellaboration follows....
  14.     
  15.     Background:  Motif expects the programmer to pass a pointer to a function whenever you make a callback, so that when, say a button is pushed, then the specified function will be called.  The function might print out "Hey, stop pushing me!"  Alright fine, but I don't want motif to call just a plain function, I want it to call a certain member function (or method) of the class that is registering the callback.  
  16.  
  17.     The Problem:  Unlike plain functions, you can't easily (or at all?) get a pointer to the member function that is complete enough to invoke the method from.  Pointers to member function usually (as far as I've seen) come in two parts, a pointer to the object & an offset points to the member.  Both are needed to invoke the member function.  
  18.     
  19.     What I've tried:  I've been able to do the following: I can get a pointer to the object, and I can the offset of the member function, which lets me do something like this:
  20.  
  21.     Pointer_To_Object->*Pointer_Offset_Of_Member_Function();
  22.  
  23. I can even pass the 'Pointer_To_Object' as client_data to the callback, letting me call a method if it is always the same, so I can do this in the motif function callback:
  24.  
  25.     Pointer_To_Object->Callback();  
  26.  
  27. This works well, allowing all of my classes to specifiy a single function as the callback, which in turn will call the 'Callback()' member function when invoked, but what if I don't always want to call 'Callback()'.  Since one class might have more than one callback (say, one for "OK" & one for "CANCEL"), how can I get motif to call a member function as a callback?
  28.  
  29.  
  30.     The QUESTION:
  31.  
  32.     1) How can I get a SINGLE pointer to a member function that can be invoked when it is passed to some third party?
  33.  
  34.     -or-
  35.  
  36.     2) Is there some clever way to get motif to call any given member function from a 'function' callback?
  37.  
  38.             Thanks,
  39.  
  40.  
  41.             JJ
  42.  
  43.             JJ Rohrer
  44.  
  45.             National Air Intelligence Center
  46.             Wright-Patterson AFB, OH
  47.  
  48. e-mail
  49. jjr189@naic.ic.gov
  50. jrohrer@msn.com
  51.  
  52. phone: 513-257-9989
  53.  
  54.     
  55.  
  56.